package com.perfma.xtest.tool;


import cn.hutool.core.util.EnumUtil;
import com.alibaba.fastjson.JSONArray;
import com.google.common.base.Joiner;
import com.google.common.base.Preconditions;
import com.google.common.base.Splitter;
import com.google.common.collect.Lists;
import com.google.common.primitives.Ints;

import java.io.File;
import java.io.FileOutputStream;
import java.math.BigDecimal;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;

/**
 * @author: junhui.si
 * @date: 2021-06-10 11:19
 **/
public class SplitDemo {
    private static final Pattern NAME_PATTERN = Pattern.compile("^[\\s.a-zA-Z\\d~!@#%^&*()_+{}|:\"<>?`\\[\\]\\-=\\\\;',\\./～！¥…（）—「」｜：“《》？·【】、；‘，。\\u4e00-\\u9fa5]+$");


    /**
     * 名称类限制：不允许输入${}
     */
    private static final Pattern NAME_PATTERN2 = Pattern.compile(".*\\$\\{(.*)\\}.*");

    public static void main(String[] args) throws Exception {
//        String firstLine = "0:15\n";
//        System.out.println(Arrays.toString(firstLine.split("[:\r\n]")));
//        firstLine = "0:15\r";
//        System.out.println(Arrays.toString(firstLine.split("[:\r\n]")));
//        firstLine = "0:15\r\n";
//        System.out.println(Arrays.toString(firstLine.split("[:\r\n]")));

//        long size = 5800000;
//        File file = new File("/Users/sijunhui/Downloads/测试文件分割/windows-7数据3.txt");
//        if (file.exists()){
//            file.delete();
//            file.createNewFile();
//        }
//
//        FileOutputStream out = new FileOutputStream(file);
//        StringBuilder sb = new StringBuilder();
//        sb.append("winUid,winPw\r\n");
//        for (int i = 1; i <= size; i++) {
//            sb.append(String.format("win_%s,win_csv_test_%s\r\n", i, i));
//            if (sb.length() % 100000 == 0 || i == size) {
//                out.write(sb.toString().getBytes());
//                sb.setLength(0);
//            }
//        }
//        System.out.println(match("左边界123待会发左边界表左边界达右边界式加减右边界时间", "左边界", "右边界"));
//        String s = "~!@#%^&*()_+{}|:\"<>?`[]-=\\;',./～！@#¥%……&*（）——+「」｜：“《》？·-=【】、；‘，。/";
//        String a = "~!@#%^&*()_+{}|:\"<>?`[]-=\\;',./～！¥…（）—「」｜：“《》？·【】、；‘，。";
//        char[] c = s.toCharArray();
//        List<Character> list = Lists.newArrayList();
//        for (int i = 0; i < c.length; i++) {
//            System.out.println(c[i] + "   " + (int) c[i]);
//            list.add(c[i]);
//        }
//        list = list.stream().distinct().collect(Collectors.toList());
//        System.out.println(Joiner.on("").join(list));

//        System.out.println(NAME_PATTERN.matcher(a).matches());
//        String url = "https://www.xx.com:11/a/b";
//        int splitIndex1 = url.indexOf("://");
//        Preconditions.checkArgument(splitIndex1 > 0, "协议格式错误");
//        int splitIndex2 = url.indexOf("/", splitIndex1 + 3);
//        HttpProtocolEnum httpProtocolEnum = EnumUtil.fromString(HttpProtocolEnum.class, url.substring(0, splitIndex1), null);
//        Preconditions.checkNotNull(httpProtocolEnum, "协议格式错误");
//        System.out.println(httpProtocolEnum);
//
//        String hostAndPort = url.substring(splitIndex1 + 3, splitIndex2);
//        List<String> hostAndPortArray = Lists.newArrayList(Splitter.on(":").omitEmptyStrings().split(hostAndPort));
//        Preconditions.checkArgument(!hostAndPortArray.isEmpty() && hostAndPortArray.size() <= 2, "域名或端口格式错误");
//        String hostName = hostAndPortArray.get(0).trim();
//        System.out.println(hostName);
//
//        int port;
//        if (hostAndPortArray.size() > 1) {
//            Preconditions.checkNotNull(Ints.tryParse(hostAndPortArray.get(1)), "端口格式错误");
//            port = Ints.tryParse(hostAndPortArray.get(1));
//        } else {
//            port = httpProtocolEnum.getPort();
//        }
//        System.out.println(port);
//
//        String path = url.substring(splitIndex2);
//        System.out.println(path);

//        BigDecimal bigDecimal = new BigDecimal("+20.11111");
//        System.out.println(bigDecimal);

//        System.out.println(JSONArray.parse(""));

        System.out.println(NAME_PATTERN2.matcher("$x{bb zx}").matches());
    }

    private static List<String> match(String input, String left, String right) {
        List<String> resultList = Lists.newArrayList();
        Pattern pattern = Pattern.compile(left + "([\\s\\S]*)" + right);
        Matcher matcher = pattern.matcher(input);
        while (matcher.find()) {
            int count = matcher.groupCount();
            for (int i = 0; i < count; i++) {
                resultList.add(matcher.group(i));
            }
        }
        return resultList;
    }

}
